from pydantic import BaseModel, Field
from typing import List, Optional


class BaseOrdersList(BaseModel):
    water_no: Optional[str] = Field(None)
    user_id: int = Field(0)
    price: float = Field(0.00)
    amount_price: float = Field(0.00)
    sale_price: float = Field(0.00)
    sale_roles: Optional[str] = Field(None)
    status: int = Field(0)
    pay_time: Optional[str] = Field(None)
    exp_time: Optional[str] = Field(None)
    is_express: int = Field(0)
    express: Optional[str] = Field(None)
    express_price: float = Field(0.00)
    receive_name: Optional[str] = Field(None)
    receive_phone: Optional[str] = Field(None)
    receive_address: Optional[str] = Field(None)
    goods: Optional[str] = Field(None)
    type: int = Field(1)
    address_id: Optional[int] = Field(0)
    remark: Optional[str] = Field(None)
    is_give: int = Field(0)
    giver_id: Optional[int] = Field(0)
    is_deposit: int = Field(0)
    deposit_price: float = Field(0.00)
    coupons: Optional[str] = Field(None)
    coupons_price: float = Field(0.00)
    refund_time: Optional[str] = Field(None)
    is_draw: int = Field(0)
    draw_id: int = Field(0)
    add_uid: int = Field(0)
    order_rate: int = Field(5)
    order_evaluations: Optional[str] = Field(None)
    is_review: int = Field(0)


class OrdersListCreate(BaseOrdersList):
    sale_roles: Optional[list] = None
    express: Optional[list] = None
    goods: Optional[list] = None


class OrdersListCreateMini(BaseModel):
    type: int = 1  ##1点单类型2商城3储值
    sku: Optional[list] = None
    address_id: Optional[int] = Field(0)
    status: Optional[int] = Field(0)


class OrdersListUpdateExpress(BaseModel):
    receive_id: Optional[int] = Field(0)
    order_id: Optional[int] = Field(0)


class OrdersListRefund(BaseModel):
    order_id: Optional[int] = Field(0)
    order_status: Optional[int] = Field(0)


class OrdersListUpdate(BaseOrdersList):
    id: int
    sale_roles: Optional[list] = None
    express: Optional[list] = None
    goods: Optional[list] = None
    coupons: Optional[list] = None

    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})


class OrdersListUpdateMini(BaseModel):
    id: int
    remark: Optional[str] = Field(None)


class OrdersListUpdateEvaluation(BaseModel):
    id: int
    order_rate: int = Field(5)
    order_evaluations: Optional[str] = Field(None)


class OrdersListPay(BaseModel):
    id: int
    is_deposit: int = Field(0)
    coupons: Optional[list] = None


class BaseOrdersGoods(BaseModel):
    order_id: int = Field(0)
    user_id: int = Field(0)
    goods_id: int = Field(0)
    price: float = Field(0.00)
    sale_price: float = Field(0.00)
    sale_roles: str = Field(None)
    num: int = Field(0)
    status: int = Field(0)
    sku_name: str = Field(None)
    sku_id: int = Field(0)
    is_express: int = Field(0)
    express_company: str = Field(None)
    express_no: str = Field(None)
    remark: str = Field(None)
    attr: Optional[str] = Field(None)
    give_type: Optional[int] = Field(0)


class OrdersGoodsCreate(BaseOrdersGoods):
    sale_roles: Optional[list] = None
    remark: Optional[list] = None
    attr: Optional[list] = Field(None)


class OrdersGoodsUpdate(BaseOrdersGoods):
    id: int
    sale_roles: Optional[list] = None
    remark: Optional[list] = None
    attr: Optional[list] = Field(None)

    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})


class BaseOrdersReceive(BaseModel):
    receive_name: str = Field(None)
    receive_phone: str = Field(None)
    receive_city: str = Field(None)
    receive_address: str = Field(None)
    is_default: Optional[bool] = False
    user_id: int = Field(0)


class OrdersReceiveCreate(BaseOrdersReceive):
    ...


class OrdersReceiveUpdate(BaseOrdersReceive):
    id: int

    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})


class BaseOrdersCar(BaseModel):
    goods_id: int = Field(0)
    price: float = Field(0.00)
    num: int = Field(0)
    user_id: int = Field(0)
    sku_id: int = Field(0)
    sku_name: str = Field(None)
    sale_price: float = Field(0.00)


class OrdersCarCreate(BaseOrdersCar):
    ...


class OrdersCarUpdate(BaseOrdersCar):
    id: int

    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})


class BaseOrdersExpress(BaseModel):
    order_id: int = Field(0)
    order_goods_id: str = Field(None)
    express_company: str = Field(None)
    express_no: str = Field(None)


class OrdersExpressCreate(BaseOrdersExpress):
    order_goods_id: Optional[list] = None


class OrdersExpressUpdate(BaseOrdersExpress):
    id: int
    order_goods_id: Optional[list] = None

    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})


class SendMessage(BaseModel):
    order_id: int = 0
    openid: Optional[str] = None
    user_id: Optional[int] = 0


class BaseOrdersWater(BaseModel):
    order_id: int = Field(0)
    amount: float = Field(0.00)
    out_trade_no: Optional[str] = Field(None)
    transaction_id: Optional[str] = Field(None)
    success_time: Optional[str] = Field(None)


class OrdersWaterCreate(BaseOrdersWater):
    ...


class OrdersWaterUpdate(BaseOrdersWater):
    id: int

    def update_dict(self):
        return self.model_dump(exclude_unset=True, exclude={"id"})
